package com.greensam.api.controller.base;

import com.greensam.domain.entity.BaseUserInfo;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

/**
 * @Author: Machengrui
 * @Date: 2024/12/24 13:35
 */
@Getter
@AllArgsConstructor
public class BaseUserDetails implements UserDetails {

    private final BaseUserInfo baseUserInfo;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return List.of();
    }

    @Override
    public String getPassword() {
        return baseUserInfo.getPassword();
    }

    @Override
    public String getUsername() {
        return baseUserInfo.getAccount();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return baseUserInfo.getState().equals(1);
    }

}
